#include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File

#include "DSP2833x_System.h"

// Initialize all system
void InitSystem(void){
	// Step 1: Initialize the system control	
	InitSysCtrl();	
		
	// Step 2. Initalize GPIO:	
	//InitSciaGpio();   
	    	
	// Step 3. Clear all interrupts and initialize PIE vector table:
	// Disable CPU interrupts 
   DINT;   
   // Initialize PIE control registers to their default state.
   // The default state is all PIE interrupts disabled and flags
   // are cleared. 
   InitPieCtrl();   
   // Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;    	   
	// Initialize the PIE vector table with pointers to the shell Interrupt 
	// Service Routines (ISR).  
   InitPieVectTable();   
}
//=========================================
// Convert from Hexadecimal number to Ascii
// Input: 0xabcd => buffer[0] = 'd', buffer[1] = 'c', ...
//=========================================
void Hex2Ascii(Uint16 Hex_data,Uint16 * buffer){
	Uint16 i,temp;
	for(i=0;i<4;i++){
		temp = (Hex_data>>(4*i)) & 0x000F;		
		if(temp>9)
			temp = temp - 10 + 'A';
		else
			temp = temp + '0';
		// Assign output			
		buffer[i] = temp;	
	};
}
// Convert Hex to Decimal
void Hex2Dec(Uint16 Hex_data, Uint16 * buffer){
	Uint16 temp,i;
	
	for(i=0;i<5;i++){
		temp = Hex_data%10;
		Hex_data = Hex_data/10;
		// Assign output
		buffer[i] = temp+'0';
	};	
	
}
